package mo.leetcode_top;

public class L324 {

    public void wiggleSort(int[] nums) {
        int[] bucket = new int[5001];
        for (int num : nums) {
            bucket[num]++;
        }
        int len = nums.length;
        int small, big;
        if ((len & 1) == 1) {
            small = len - 1;
            big = len - 2;
        } else {
            big = len - 1;
            small = len - 2;
        }
        int j = 5000;
        for (int i = 1; i <= big; i += 2) {
            while (bucket[j] == 0) {
                j--;
            }
            nums[i] = j;
            bucket[j]--;
        }
        for (int i = 0; i <= small; i += 2) {
            while (bucket[j] == 0) {
                j--;
            }
            nums[i] = j;
            bucket[j]--;
        }
    }

}
